package com.zhima.controller.admin;

import com.zhima.dto.ZhimaOjResult;
import com.zhima.entity.OjLabel;
import com.zhima.service.OjLabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.zhima.dto.ZhimaOjResult.success;

@RestController
@RequestMapping("/label/admin")
public class OjLabelAdminController {
    @Autowired
    private OjLabelService ojLabelService;

    /**
     * 为id为parentId的标签增加子标签
     *
     * @param labelName
     * @param parentId
     * @return
     */
    @PostMapping("/{labelName}/{parentId}")
    public ZhimaOjResult createNewLabel(@PathVariable("labelName") String labelName, @PathVariable("parentId") Long parentId) {
        return success(ojLabelService.createNewLabel(labelName, parentId));
    }

    /**
     * 增加顶级标签
     *
     * @param labelName
     * @return
     */
    @PostMapping("/{labelName}")
    public ZhimaOjResult createNewLabel(@PathVariable("labelName") String labelName) {
        return success(ojLabelService.createNewLabel(labelName, null));
    }

    /**
     * 删除指定标签
     *
     * @param labelId
     * @return
     */
    @DeleteMapping("/{labelId}")
    public ZhimaOjResult deleteLabelById(@PathVariable("labelId") Long labelId) {
        return success(ojLabelService.deleteLabelById(labelId));
    }

    /**
     * 更新标签信息
     *
     * @param ojLabel
     * @return
     */
    @PutMapping
    public ZhimaOjResult updateLabel(@RequestBody OjLabel ojLabel) {
        return success(ojLabelService.updateLabel(ojLabel));
    }
}
